﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class NV_CC_DAL: BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            var sql = @" select * from NV_CC";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Insert(object obj)
        {
            var o = (NV_CC)obj;
            string sql = @" 
                            set dateformat dmy; 
                            insert into NV_CC (MA_NV, MA_CC, NGAY_BD, NGAY_KT) values ('{0}', '{1}', '{2}', '{3}') 
                            ";
            sql = string.Format(sql, o.MA_NV, o.MA_CC, o.NGAY_BD, o.NGAY_KT);
            return ExecuteNonQuery(sql) > 0 ? true: false;
        }

        public bool Update(object obj)
        {
            var o = (NV_CC)obj;
            string sql = @" set dateformat dmy;
                            update NV_CC set MA_NV = '{0}', MA_CC = '{1}', NGAY_BD = '{2}', NGAY_KT = '{3}'
                            WHere MA_NV = '{0}' AND MA_CC = '{1}'
                            ";
            sql = string.Format(sql, o.MA_NV, o.MA_CC, o.NGAY_BD, o.NGAY_KT);
            return ExecuteNonQuery(sql) > 0 ? true:false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        //xoa dong data co khoa chinh la 2 thuok tinh

        public bool XOA(string id, string ip)
        {

            string sql = "DELETE  FROM NV_CC WHERE MA_NV = '{0}' AND MA_CC = '{1}' ";
            sql = string.Format(sql, id, ip);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        //SUA DATA  CO KHOA LA 2 THUOK TINH

        public bool SUA(string NV, string CC)
        {
            string sql = @" set dateformat dmy;
                            update NV_CC set MA_NV = '{0}', MA_CC = '{1}', NGAY_BD = '{2}', NGAY_KT = '{3}'
                            WHERE MA_NV = '{0}' AND MA_CC = '{1}'
                            ";
            sql = string.Format(sql, NV, CC);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        // LOAD DATA LEN COMBOBOX NHAN VIEN

        public DataTable Select_NV()
        {
            string sql = @" SELECT MA_NV AS id, HOTEN_NV as ten FROM NHAN_VIEN";
            return ExecuteQuery(sql);
        }

        // LOAD DATA LEN COMBOBOX chung cu

        public DataTable Select_CC()
        {
            string sql = @" SELECT MA_CC AS id, TEN_CC as ten FROM CHUNG_CU";
            return ExecuteQuery(sql);
        }
    }
}
